package com.zhl.multi_data_source_demo;

import com.zhl.multi_data_source_demo.service.Service;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ApplicationContext;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@MapperScan(basePackages = "com.zhl.multi_data_source_demo.dao")
public class MultiDataSourceDemoApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(MultiDataSourceDemoApplication.class, args);
    }

    @Autowired
    private ApplicationContext applicationContext;
    @Override
    public void run(ApplicationArguments args){
        Service service = (Service) applicationContext.getBean("service");
        service.contextLoads2();
        service.contextLoads21();
    }
}
